<?php

namespace apiend\modules\user\controllers;

use Yii;
use apiend\components\Controller;
use apiend\modules\user\models\FavoriteDynamicSearch;
use apiend\modules\user\models\FavoriteProductSearch;
use apiend\modules\user\models\FavoriteStoreSearch;
use apiend\modules\user\models\FavoriteArticleSearch;
use apiend\modules\user\models\FavoriteRemoveForm;

/**
 * 用户收藏列表
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class FavoriteController extends Controller {

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            '*' => ['GET'],
            'remove' => ['POST'],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * 用户收藏的帖子动态
     * @return mixed
     */
    public function actionDynamic() {
        $model = new FavoriteDynamicSearch();
        $model->uid = $this->uid;
        return $model->search();
    }

    /**
     * 用户收藏的商品
     * @return mixed
     */
    public function actionProduct() {
        $model = new FavoriteProductSearch();
        $model->user_id = $this->uid;
        return $model->search();
    }
    
    /**
     * 用户收藏的店铺
     * @return mixed
     */
    public function actionStore() {
        $model = new FavoriteStoreSearch();
        $model->user_id = $this->uid;
        return $model->search();
    }
    
    /**
     * 用户收藏的商品
     * @return mixed
     */
    public function actionArticle() {
        $model = new FavoriteArticleSearch();
        $model->user_id = $this->uid;
        return $model->search();
    }

    /**
     * 用户收藏的商品
     * @return mixed
     */
    public function actionRemove() {
        $model = new FavoriteRemoveForm();
        $model->user_id = $this->uid;
        if (!$model->load(Yii::$app->request->post(), '')) {
            parent::error('提交的信息不完整');
        }
        return $model->save();
    }

}
